package com.txzt.gaea.flow.service;

import com.txzt.base.core.RtnInfo;
import com.txzt.gaea.common.base.service.BaseService;
import com.txzt.gaea.common.page.PageInfoBT;
import com.txzt.gaea.flow.dto.FlowDefinitionQueryDTO;
import com.txzt.gaea.flow.model.*;
import com.txzt.gaea.flow.vo.FlowBizStepVo;
import com.txzt.gaea.flow.vo.FlowDefinitionVo;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface FlowService extends BaseService<FlowDefinition> {

    /**
     * 分页查询
     * @param flowDefinitionQueryDTO
     * @return RtnInfo<PageInfoBT<FlowDefinitionVo>>
     */
    RtnInfo<?> pageList(FlowDefinitionQueryDTO flowDefinitionQueryDTO);

    /**
     * 新增流程
     * @param flowDefinition
     * @return int
     */
    int save(FlowDefinition flowDefinition);

    int insertInfo(FlowDefinition flowDefinition);

    /**
     * 修改流程
     * @param flowDefinition
     * @return int
     */
    int update(FlowDefinition flowDefinition);

    /**
     * 查重名  依照 flowName 和 flowFlag 字段
     * @param flowDefinition
     * @return boolean
     */
    boolean checkFlowNameAndFlag(FlowDefinition flowDefinition);

    /**
     * 查询详情 依照 id
     * @param id
     * @return FlowDefinition
     */
    FlowDefinition getFlowInfo(Long id);

    /*  业务流程逻辑处理  */

    /**
     * 开启审批流程
     * @param bizId 业务ID
     * @param bizTable  业务表（用于更新业务表状态）
     * @param bizStatusCol 业务表状态字段名称
     * @param bizBackStatus 业务回退状态
     * @param bizPassStatus 业务通过状态
     * @param flowFlag  流程标识
     * @return Long 业务流程主ID
     */
    Long startFlow(Long bizId, String bizTable, String bizStatusCol,
                      Integer bizBackStatus, Integer bizPassStatus, String flowFlag);

    int insertFlowBiz(FlowBiz flowBiz);
    int updateFlowBiz(FlowBiz flowBiz);
    int insertFlowBizStep(FlowBizStep flowBizStep);
    int updateFlowBizStep(FlowBizStep flowBizStep);

    /**
     * 审批流程流转
     * @param bizId 业务ID
     * @param flowFlag 流程标识
     * @param status 审核状态 1 通过 2 打回 3 不通过
     * @param comment 审批内容
     * @return boolean
     */
    boolean nextStep(Long bizId, String flowFlag, int status, String comment);

    /**
     * 审批流程流转
     * @param bizFlowId 业务流程ID
     * @param status 审核状态 1 通过 2 打回 3 不通过
     * @param comment 审批内容
     * @return boolean
     */
    boolean nextStep(Long bizFlowId, int status, String comment);

    /**
     * 获取审批步骤
     * @param bizId 业务ID
     * @param flowFlag 流程标识
     * @return List<FlowBizStepVo>
     */
    List<FlowBizStepVo> getFlowBizStep(Long bizId, String flowFlag);

    /**
     * 获取审批步骤
     * @param bizFlowId 业务流程ID
     * @return List<FlowBizStepVo>
     */
    List<FlowBizStepVo> getFlowBizStep(Long bizFlowId);


    /**
     *
     * 开启审批流程(升级版)
     *
     * @param bizId 业务数据id
     * @param bizTable 业务数据表
     * @param bizStatusCol 业务数据状态字段名
     * @param bizBackStatus 业务数据退回修改状态
     * @param bizPassStatus 业务数据通过状态
     * @param bizRejectStatus 业务数据不通过状态
     * @param bizRevocationStatus 业务数据撤回状态
     * @param flowFlag 流程标识
     * @param deptId 业务数据所属部门
     * @return
     */
    Long startFlowUpgrade(Long bizId, String bizTable, String bizStatusCol,
                          Integer bizBackStatus, Integer bizPassStatus, Integer bizRejectStatus, Integer bizRevocationStatus, String flowFlag, Long deptId);


    /**
     *
     * @param flowBizModel
     * @return
     */
    boolean nextStepUpgrade(FlowBizModel flowBizModel);

    @Transactional(rollbackFor = Exception.class)
    int nextStepOnlyForBackCusOrBack(Long bizFlowId, List<FlowBizStep> stepList, String flowType);

    /**
     *
     * @param bizFlowId
     * @return
     */
    int nextStepOnlyForBack(Long bizFlowId);

    @Transactional(rollbackFor = Exception.class)
    int nextStepOnlyForBack(Long bizFlowId, List<FlowBizStep> stepList);

    /**
     * 退回修改
     *
     * @param bizFlowId
     * @return
     */
    int nextStepOnlyForBackPlan(Long bizFlowId, String flowType, List<FlowBizStep> stepList);

    boolean revocation(Long flowBizId, Long stepId);

    List<FlowBizStep> getFlowStepListDesc(Long flowId);

    FlowBiz getFlowBiz(Long flowId);

    List<FlowStep> showStepList(String flowType, String flowFlag);

    @Transactional(rollbackFor = Exception.class)
    Long startFlowCustomizationOrStandard(Long bizId, String bizTable, String bizStatusCol, Integer bizBackStatus,
                                          Integer bizPassStatus, Integer bizRejectStatus, Integer bizRevocationStatus,
                                          String flowFlag, Long deptId, List<FlowBizStep> stepList, String flowType);

    Long startFlowCustomization(Long bizId, String bizTable, String bizStatusCol,
                                Integer bizBackStatus, Integer bizPassStatus, Integer bizRejectStatus,
                                Integer bizRevocationStatus, String flowFlag, Long deptId, List<FlowBizStep> stepList);

}
